<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body >
<form class="layui-form" action="javascript:;" lay-filter=""  >
    <input type="hidden" lay-submit lay-filter="down2007">
    <div class="layui-form-item">

    </div>
</form>
</body>

<script type="text/javascript">

    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','formSelects' ,'element','laydate','laytpl','layedit','util','code'], function() {
        var $ = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layer = layui.layer;
        var table = layui.table;
        var element = layui.element;
        var laydate= layui.laydate;
        var laytpl = layui.laytpl;
        var layuiutil = layui.util
        var layedit = layui.layedit;

        var panelId
        var indexLoad = layer.load();

        $.getJSON(basePath+"/xdWidgetPanel/viewPanelTableLast"+urlParam,function(rst){
            layer.close(indexLoad)
            if(rst.code !=0){
                //layer.alert(rst.msg,{icon:1})
                layer.alert("异常:<br>"+rst.msg,{icon:2})
                //layer.alert(rst.msg,{icon:3})
                //layer.alert(rst.msg,{icon:4})
                //layer.alert(rst.msg,{icon:5})
                //layer.alert(rst.msg,{icon:6})
                //layer.alert(rst.msg,{icon:7})
                return
            }

            $.each(rst.formItem,function(index,item){
                $(".layui-form-item").append(item.html)

                if(item.classFlag == "xd-date"){
                   laydate.render({elem:"#"+item.name,type:item.type,value: new Date(commonUtil.setDefaultDate(item.defaultValue)),theme:item.theme})
                }else if(item.classFlag =="xd-select" ){
                    var param = item
                    if(item.serverFlag){
                        formSelects.data(item.name, 'server', {//远程根据 keyword 查询
                            type:"post",
                            data:param,
                            searchUrl:basePath+"/xdWidgetSelect/selectView",
                            success: function(id, url, searchVal, result){           //使用远程方式的error回调
                                if(result.code !=0){
                                    layer.alert(result.msg,{icon: 2})
                                }
                            }
                        });
                    }else{
                        formSelects.render(item.name)
                    }
                }
            })

            form.render('checkbox');
            form.render('select');
            form.render('radio');


            $("body").append(rst.panel)
            var tableOption = rst.table
            panelId = rst.panelId
            tableOption.done = function(res, curr,count){
                if(!tableOption.page){
                    commonUtil.mergeCell(tableOption.id,tableOption.mergeField)
                }
            }
            if(tableOption.queryFlag){
                table.render(tableOption)
            }

            table.on("toolbar("+tableOption.id+")",function(obj){
                var event = obj.event;
                switch (event){
                    case "downLoad":
                        $("[lay-filter=down2007]").click()
                        break;
                }
            })

        })

        form.on("submit(down2007)",function(obj){
            var loadIndex =  layer.load()
            var url = basePath+"/xdWidgetPanel/createExcel2007?panelId="+panelId ;
            $.post(url,obj.filed,function(rst){
                layer.close(loadIndex)
                console.log(rst)
                if(rst.code == 0){
                    window.open(basePath+"/specialDownLoad/doXLSXByTempFileAndFileName?fileName="+rst.data.fileName +"&tempFile="+rst.data.tempFile)
                }else{
                    layer.alert("下载异常：<br>"+rst.msg,{icon:2})
                }
            },"json")
        })
    });




</script>
